package cn.tedu.controller;

import cn.tedu.pojo.Ad;
import cn.tedu.pojo.Coupon;
import cn.tedu.pojo.Item;
import cn.tedu.serivce.IAdService;
import cn.tedu.serivce.ICouponService;
import cn.tedu.serivce.IItemService;
import cn.tedu.vo.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测试异步 线程池控制器
 * @author Kiven
 * @date 20220309
 */
@RestController
@RequestMapping("/web/index")
@Slf4j
public class IndexController {

    @Autowired
    private IItemService itemService;

    @Autowired
    private ICouponService couponService;

    @Autowired
    private IAdService adService;




    @GetMapping
    public JsonResult findIndexList(){

        long startTime = System.currentTimeMillis();
        //制造业务需求. 现在要把首页的信息加载到redis缓存中,否则就多线程查询多个业务.再返回
        //其中需要商品list .优惠券list.广告轮播.
        List<Item> itemList = itemService.getItemList();// 1003
        List<Coupon> coupon = couponService.getCoupon();//1045
        List<Ad> adList = adService.getAdList();//1010
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("itemList",itemList);
        resultMap.put("couponList",coupon);
        resultMap.put("adList",adList);
        long endTime = System.currentTimeMillis();
        log.debug("总计用时:"+(endTime - startTime));
        return new JsonResult(resultMap);
    }



}
